package Exercise;

import java.util.Arrays;

public class ExchangeNum {

    public static int[] reOrderArray(int[] array) {
        if (array == null || array.length < 3)
            return array;
        int temp;
        boolean isChange;
        for (int i = 0; i < array.length; ++i) {
            isChange = false;
            for (int j = 0; j < array.length - 1; ++j) {
                if (array[j] % 2 == 0 && array[j + 1] % 2 == 1) {
                    temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                    isChange = true;
                }
            }
            if (!isChange)
                break;
        }
        return array;
    }

    public static void main(String[] args) {
        int[] array = {1, 2, 5, 4, 3, 8, 6, 7};
        int[] temp = reOrderArray(array);
        System.out.println(Arrays.toString(temp));
    }

}
